import pymysql

class DB:
    def __init__(self):
        self.conn = pymysql.connect(host='localhost',port=3306,user='root',password='mysql',db='workf',charset='utf8',cursorclass = 
        pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()


    # 添加，修改，删除
    def update(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()

    # 查询单个
    def find(self,sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchone()
        return res

    # 查询所有
    def find_all(self,sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchall()
        return res

    # 关闭
    def close(self,sql):
        self.cousor.close()
        self.conn.close()

db1 = DB()